const state = {
  token: null,
  userInfo: null,
  isRegister: false,
}

const mutations = {
  SET_TOKEN(state, value){
    if(typeof value !== 'string'){
      throw new Error('token is not a string')
    }
    state.token = value
  },
  SET_USER_INFO(state, value){
    if(typeof value !== 'object'){
      throw new Error('userInfo is not an object')
    }
    state.userInfo = value
  }
}

const actions = {
  setToken({ commit }, value){
    commit('SET_TOKEN', value)
  },
  setUserInfo({ commit }, value){
    commit('SET_USER_INFO', value)
  }
}

export default {
  state,
  mutations,
  actions
}
